﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using DiarySocial.Models;
using WebMatrix.WebData;

namespace DiarySocial.App_Start
{
    public class InitialSampleData
    {
        public static void RegisterSampleData()
        {
            DiaryEnties context = new DiaryEnties();
            if (InitSampleUser())
            {
                InitSampleFriendRelationShip(context);
            }
        }
        private static bool InitSampleUser() {
            var roles = (SimpleRoleProvider)Roles.Provider;
            var membership = (SimpleMembershipProvider)Membership.Provider;
            if (membership.GetUser("user0", false) == null)
            {
                var defautPassword = "12345678";
                var list = new string[100];
                int count = 0;
                // haven't init users
                for (int i = 0; i < 100; i++)
                {
                    var username = "user" + i.ToString();
                    if (membership.GetUser(username, false) == null)
                    {
                        membership.CreateUserAndAccount(username, defautPassword);
                    }
                    list[count++] = username;
                }
                roles.AddUsersToRoles(list, new[] { "User" });
                return true;
            }
            return false;
        }
        private static void InitSampleFriendRelationShip(DiaryEnties context)
        {
            
        }
    }
}